package com.stevens.triangles;

import java.util.Arrays;
import java.util.Scanner;

public class PiotrTriangles extends TrianglesBase {
	
	public PiotrTriangles(double[] triangleSides) {
		super(triangleSides);
	}

	@Override
	public String kindOfTriangle() {
		if(this.triangleSides.length > 3) return kTooManySidesError;
		if(this.triangleSides.length < 3) return kTooFewSidesError;
			
		String string;
		
		for(int i = 0; i < 3; i++) 
			if(this.triangleSides[i] <= 0) 
				return kInvalidSideError;
		
		Arrays.sort(this.triangleSides);
		if (this.triangleSides[0] + this.triangleSides[1] <= this.triangleSides[2])
			return kInvalidTriangleError;
		
		int equalSides = 0;
		if (this.triangleSides[0] == this.triangleSides[1])
			equalSides++;
		if (this.triangleSides[0] == this.triangleSides[2])
			equalSides++;
		if (this.triangleSides[1] == this.triangleSides[2])
			equalSides++;
		
		switch (equalSides) {
		case 0:
			string = "Scalene";
			break;
		case 1:
			string = "Isosceles";
			break;
		case 3:
			string = "Equilateral";
			break;
		default:
			string = "";
		}
		
		/* calculate pythagorean theorem with 0.01 leniency */
		if(Math.abs(Math.pow(this.triangleSides[0], 2) 
				  + Math.pow(this.triangleSides[1], 2) 
				  - Math.pow(this.triangleSides[2], 2)) < 0.001) {
			string += " Right Triangle";
		} else string += " Triangle";
		return string;
	}
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		double[] input = new double[3];
		for(int i = 0; i < 3; i++) {
			System.out.print("Enter side length: ");
			input[i] = in.nextDouble();
		}	
		PiotrTriangles tri = new PiotrTriangles(input);
		System.out.println("\n"+tri.kindOfTriangle()+"\n");
	}
}
